package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CpSite;
import com.ruoyi.system.service.ICpSiteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 新增比赛场地Controller
 *
 * @author zhangjinlei
 * @date 2022-05-12
 */
@RestController
@RequestMapping("/system/site")
public class CpSiteController extends BaseController
{
    @Autowired
    private ICpSiteService cpSiteService;

    /**
     * 查询新增比赛场地列表
     */
    @PreAuthorize("@ss.hasPermi('system:site:list')")
    @GetMapping("/list")
    public TableDataInfo list(CpSite cpSite)
    {
        startPage();
        List<CpSite> list = cpSiteService.selectCpSiteList(cpSite);
        return getDataTable(list);
    }


    /**
     * 导出新增比赛场地列表
     */
    @PreAuthorize("@ss.hasPermi('system:site:export')")
    @Log(title = "新增比赛场地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CpSite cpSite)
    {
        List<CpSite> list = cpSiteService.selectCpSiteList(cpSite);
        ExcelUtil<CpSite> util = new ExcelUtil<CpSite>(CpSite.class);
        util.exportExcel(response, list, "新增比赛场地数据");
    }

    /**
     * 获取新增比赛场地详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:site:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cpSiteService.selectCpSiteById(id));
    }

    /**
     * 新增新增比赛场地
     */
    @PreAuthorize("@ss.hasPermi('system:site:add')")
    @Log(title = "新增比赛场地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpSite cpSite)
    {
        return toAjax(cpSiteService.insertCpSite(cpSite));
    }

    /**
     * 修改新增比赛场地
     */
    @PreAuthorize("@ss.hasPermi('system:site:edit')")
    @Log(title = "新增比赛场地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpSite cpSite)
    {
        return toAjax(cpSiteService.updateCpSite(cpSite));
    }

    /**
     * 删除新增比赛场地
     */
    @PreAuthorize("@ss.hasPermi('system:site:remove')")
    @Log(title = "新增比赛场地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cpSiteService.deleteCpSiteByIds(ids));
    }
}
